<?php

class AdminAreaModule extends AWebModule
{
	public function init()
	{
		// this method is called when the module is being created
		// you may place code here to customize the module or the application

		// import the module-level models and components
		$this->setImport(array(
			'adminArea.models.*',
			'adminArea.components.*',
			'adminArea.components.ATableEditor.*'
		));

		$theme = 'adminArea'.DIRECTORY_SEPARATOR.'classic';
		Yii::app()->setTheme($theme);
		$this->setViewPath(Yii::app()->getTheme()->viewPath.DIRECTORY_SEPARATOR.$this->name);
	}

	public function beforeControllerAction($controller, $action)
	{
		if(parent::beforeControllerAction($controller, $action))
		{
			if(!Yii::app()->user->checkAccess('administrator') && Yii::app()->controller->id!='login'){
				echo 'access denied';
				Yii::app()->request->redirect('/adminArea/login/accessDenied');
				exit;
			}
			$this->registerJsCss();
			return true;
		}
		else
			return false;
	}

	private function registerJsCss(){
		$jquery = Yii::app()->assetManager->publish(
			Yii::getPathOfAlias('system.web.js.source.*'), true, -1, YII_DEBUG
		);
		Yii::app()->getClientScript()->registerScriptFile($jquery . '/jquery'.(YII_DEBUG ? '' : '.min').'.js');
		$jqueryUi = Yii::app()->assetManager->publish(
			Yii::getPathOfAlias('ext.jquery.plugins.*'), true, -1, YII_DEBUG
		);
		Yii::app()->getClientScript()->registerScriptFile($jqueryUi . '/jquery-ui/jquery-ui.custom.min.js');
		Yii::app()->getClientScript()->registerCssFile($jqueryUi . '/jquery-ui/css/webmind/jquery-ui.custom.css');
	}
}
